package com.yanqu.road.web.mgr;

import com.yanqu.road.logic.bussiness.config.MallBussiness;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.manger.MultipleLanguageMgr;
import com.yanqu.road.server.manger.ServerLanguageMgr;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MallMgr extends TempMgr {

	private static Map<Integer, MallInfo> mallInfoMap;

	public boolean init() throws Exception {
		return reload();
	}

	@Override
	public boolean reloadConfig() {
		//重新加载语言
		ServerLanguageMgr.reloadLanguage();
		mallInfoMap = MallBussiness.getMallInfo();
		return true;
	}

	@Override
	public boolean reloadData() throws Exception {
		return true;
	}

	@Override
	public boolean stop() {
		return false;
	}

	public static MallInfo getMallInfoByMallId(int mallId) {
		if (mallInfoMap.containsKey(mallId)) {
			return mallInfoMap.get(mallId);
		}
		return ActivityMallMgr.getMallInfo(mallId);
	}

	/**
	 * 获取商品名称
	 */
	public static String getMallName(MallInfo mallInfo, String language) {
		if (null == mallInfo) {
			return "";
		}
		if (mallInfo.getActivityId() > 0) {
			return ServerLanguageMgr.getContent(mallInfo.getMallName(), language);
		} else {
			return MultipleLanguageMgr.getContent(mallInfo.getMallName(), language);
		}
	}

	public static Map<String,MallInfo> getRechargeCondition() {
		Map<String,MallInfo> dataMap  = new HashMap<>();
		for (MallInfo info : mallInfoMap.values()) {
			if (info.getRechargeId() > 0) {
				String mallName = info.getMallName();
				if (dataMap.containsKey(mallName)) {
					continue;
				}
				dataMap.put(mallName, info);
			}
		}
		return dataMap;
	}
}
